﻿using Abp.Dependency;
using Castle.Core;
using System.Collections.Generic;
using System.Linq;

namespace AbpProjectTemplate.Components.Payments
{
    /// <summary>
    /// 支付管理器
    /// </summary>
    public class PaymentManager : ISingletonDependency
    {
        public IEnumerable<IPaymentApi> Apis { get; private set; }

        public PaymentManager(IEnumerable<IPaymentApi> paymentApis)
        {
            this.Apis = paymentApis;
        }

        public IPaymentApi GetApi(PaymentType paymentType)
        {
            var api = this.Apis.FirstOrDefault(t => t.PaymentType == paymentType);
            if (api == null)
                throw new AppUserFriendlyException($"不存在指定类型({paymentType})的支付接口。");
            return api;
        }
    }
}
